package com.itheima.work.day5;

import java.math.BigDecimal;

public class Test1_1 {
    public static void main(String[] args) {
        double[] arr = {0.1,0.2,2.1,3.2,5.56,7.21};
        //请编程计算它们的总值及平均值(四舍五入保留小数点后2位)
        BigDecimal sum = new BigDecimal("0.0");
        for (int i = 0; i < arr.length; i++) {
            sum = sum.add(new BigDecimal(String.valueOf(arr[i])));
        }
        System.out.println("总值 sum = " + sum.doubleValue());
        BigDecimal bd2 = new BigDecimal(String.valueOf(arr.length));
        double avg = sum.divide(bd2,2,BigDecimal.ROUND_HALF_UP).doubleValue();
        System.out.println("平均值 avg = " + avg);

    }
}
